package br.com.sga.util.email;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.ResourceBundle;
//import javax.mail.internet.AddressException;
//import org.apache.commons.mail.EmailAttachment;
//import org.apache.commons.mail.EmailException;
//import org.apache.commons.mail.MultiPartEmail;

/**
 *
 * @author Roberta
 */
public class Email {

    private String emailFrom;
    private String emailFromN;
    private String autentcEmail;
    private String autentcSenha;
    private String host;
    private int porta;
    private String msgSufixo;

    public Email() {
        ResourceBundle p = ResourceBundle.getBundle("rn.emailDados");
        host = p.getString("HostName");
        emailFrom = p.getString("From");
        emailFromN = p.getString("FromName");
        autentcEmail = p.getString("Authentication");
        autentcSenha = p.getString("Senha");
        porta = Integer.parseInt(p.getString("Port"));
        msgSufixo = p.getString("MsgSufixo");
    }
/*
    public void enviaEmail(ArrayList<String> destinatarios,String assunto,String conteudo,String anexo,String arquivo) throws EmailException, AddressException {
        Iterator iterador;
        try {
            iterador = destinatarios.iterator();            

            //  StringTokenizer stPara = new StringTokenizer(destino, ",");
            // while (stPara.hasMoreTokens()) {
            MultiPartEmail email = new MultiPartEmail();
            email.setHostName(host); // o servidor SMTP para envio do e-mail                
            // email.addTo(stPara.nextToken().trim()); //destinatÃ¡rio  
            while (iterador.hasNext()) {
                String endereco = iterador.next().toString();
                email.addTo(endereco);
            }
            
            email.setFrom(emailFrom, emailFromN); // remetente  
            email.setSubject(assunto + "."); // assunto do e-mail  
            email.setMsg(conteudo + "\n" + msgSufixo); //conteudo do e-mail  
            email.setAuthentication(autentcEmail, autentcSenha);
            email.setSmtpPort(porta);
            if (!anexo.equals("")) {
                EmailAttachment attachment = new EmailAttachment();
                attachment.setPath(anexo); //caminho da imagem
                attachment.setName(arquivo);
                attachment.setDisposition(EmailAttachment.ATTACHMENT);
                // attachment.setDescription("Anexo");
                email.attach(attachment); //Anexo do e-mail.
            }
            email.setSSL(true);
            email.setTLS(true);
            email.setDebug(true);
            email.send();
            //  }
        } catch (EmailException ex) {
            throw new EmailException("Não foi possível enviar email.\nErro: " + ex);
        }
    }
    * */
}
